package com.hyc.cloud.controller;

import com.hyc.cloud.service.PaymentService;
import com.netflix.hystrix.contrib.javanica.annotation.DefaultProperties;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@Slf4j
@DefaultProperties(defaultFallback = "payment_Global_FallbackMethod")
public class OrderHystrixController {
    @Resource
     private PaymentService paymentHystrixService;

    @GetMapping(value = "/consumer/payment/hystrix/ok/{id}")
    public String paymentinfo_ok (@PathVariable("id") Integer id){
        String res = paymentHystrixService.paymentinfo_ok(id);
        return res;
    }
    @HystrixCommand
    @GetMapping(value = "/consumer/payment/hystrix/timeout/{id}")
    public String paymentinfo_timeout (@PathVariable("id") Integer id){
        //int i = 10/0;
        String res = paymentHystrixService.paymentinfo_timeout(id);
        return res;
    }
    //一对一的降级处理
    public String paymentinfo_timeoutHandler(Integer id){

        return "线程池    " +Thread.currentThread().getName()+" paymentinfo_timeoutHandler提醒您   id"+id +"方法暂时不能使用抱歉";
    }
    //下面是全局fallback方法
    public String payment_Global_FallbackMethod(){
        return "Global异常处理信息，请稍后再试,(┬＿┬)";
    }

}
